{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9ea140a0-9101-4fed-a5e8-91dffc321b22",
   "metadata": {},
   "source": [
    "# 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0c0b86f5-f720-422a-848f-c4736a1dbbbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 函数的例子\n",
    "\n",
    "def circle_area(radius):\n",
    "    return radius**2*3.14159226\n",
    "#圆的面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c186ce70-f662-482a-bc62-941586ea7ca9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28.27433034\n"
     ]
    }
   ],
   "source": [
    "print(circle_area(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f73a82df-8549-41b9-b67f-68344a0a86b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def area_triangle(long,high):\n",
    "    area =(long*high)/2\n",
    "    return area\n",
    "#三角形的面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8a8077a7-32aa-48fe-adab-24c57bdbefb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.0\n"
     ]
    }
   ],
   "source": [
    "print (area_triangle(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "93a39032-3318-4f3f-a9c2-d0acc3ea64e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cylinder_area(r,h,pi=3.1415926535):\n",
    "    area =(circle_area(r)*2+2*pi*r*h)\n",
    "    return area\n",
    "#圆柱体的面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "46fa6202-f5f1-40e1-ae51-84f8d3fd0afc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "131.95488468000002\n"
     ]
    }
   ],
   "source": [
    "print(cylinder_area(3,4,3.141926))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "aa01e7b0-e0d2-4621-9d22-130100d34be2",
   "metadata": {},
   "outputs": [],
   "source": [
    "#阶乘\n",
    "\n",
    "def factorial(num):\n",
    "    j =1\n",
    "    for i in range (1,num+1):\n",
    "        j=i*j\n",
    "    return j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "1f347779-432f-41b0-8844-8447b76cd02c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120\n"
     ]
    }
   ],
   "source": [
    "print(factorial(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c3949bfc-f89a-4847-b82b-54bcf975d4ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "#累加\n",
    "def sum(n):\n",
    "    j=0\n",
    "    for i in range(1,n+1):\n",
    "        j =j+i\n",
    "    return j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "ea11ed7a-d1a6-4ff7-8c20-10033e4eb34c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n"
     ]
    }
   ],
   "source": [
    "print (sum(100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "6e722926-1b24-44dd-9953-ebda08a5190b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def function_pi(number):\n",
    "    pi=0\n",
    "    for i in range (1,number+1,2):\n",
    "        pi=(pi+((-1)**((i+3)/2))/i)\n",
    "        \n",
    "    return pi*4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "8415b5dd-8580-4afa-90db-537dd0b77a26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.141590653589692\n"
     ]
    }
   ],
   "source": [
    "print (function_pi(999999))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cf94b16-27e4-44f0-9a1b-2a6f1d582e3d",
   "metadata": {},
   "source": [
    "# 一个二进制位数值，1bit\n",
    " 8位二进制，1byte=2**8字节\n",
    "1KB\n",
    "1MB\n",
    "1GB\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ced131f-5dcc-4f9c-9464-1d1e09127f2b",
   "metadata": {},
   "source": [
    "# PYTHON 中数据分析的概述\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "49ddbda1-03a1-4588-aae2-a4a25721dc9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "##数值的存储"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bc6c36d8-9d3f-4604-a65e-a09774be0297",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 个人计算机的内存是16GB，请问可以保存多少个字符\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0721c5b5-ca13-4987-ae25-f456dd65ed2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17179869184\n"
     ]
    }
   ],
   "source": [
    "print (16*1024*1024*1024)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b8db8158-5cf4-40a0-a015-30e4d9d8e0f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#请问一张照片高清彩色照片需要占用4.3MB，可以储存多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0171f95a-482d-456f-9147-ac0db1a9024a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3810.232558139535\n"
     ]
    }
   ],
   "source": [
    "print((16*1024)/4.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bea324b9-bd9c-47ed-ad9f-57f1d671c348",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 高清电影一部有3.3GB，请问pc可以储存多少电影"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8269a231-25dd-4507-9dd0-ec2141f45120",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "156.06060606060606\n"
     ]
    }
   ],
   "source": [
    "print(515/3.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4695f989-121e-4c9d-9a66-a7ac98f5546a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "453.27934494250906\n"
     ]
    }
   ],
   "source": [
    "print(12*1024*1024*1024/28425963)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8cb56878-dc59-4048-a559-eaf5f17adc07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "667.2044696269961\n"
     ]
    }
   ],
   "source": [
    "print (1.1*1024*1024*1024*1024/1812731847)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7cf604c-c83c-4a75-a217-dc432234df8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#import numpy as np\n",
    "#import pandas as pd\n",
    "#import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9487d56f-2fbb-4630-94b4-6e200ac35f7d",
   "metadata": {},
   "source": [
    "# 作业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aab2f1de-99bb-4adf-9676-ecb9b77122a2",
   "metadata": {},
   "source": [
    " ##给小学一年级的同学设计一个教学辅助软件，可以自动出10道个位数加法、减法练习题。10题中，出加法，减法题通过随机方法来判断。在减法时不能出现答案是负数的情况，就是你需要判断给出的数据的大小，确保答案不出现负数。在10题完成后，自动判断总数，如果分数>=90, 显示“太棒了”，>60 <90的情况下，显示“真不错”。 如果<60，则输出“要加油”。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5ac2963-ef6c-48db-9072-f36984e6f8a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8 - 0 =\n",
      "请确保输入的是一个整数\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "score =0\n",
    "times =1\n",
    "while times<=10:\n",
    "    num1 =random.randint(0,9)\n",
    "    num2 =random.randint(0,9)\n",
    "    ope =random.choice(['+','-'])\n",
    "    if ope == '-':\n",
    "        if num1-num2<0:\n",
    "            continue;\n",
    "        else:\n",
    "            print(num1,\"-\",num2,\"=\")\n",
    "            answer =num1-num2\n",
    "    if ope == '+':\n",
    "        print(num1,\"+\",num2,\"=\")\n",
    "        answer =num1+num2\n",
    "    cs =0\n",
    "    while True:\n",
    "        try:\n",
    "            user_answer =int(input(\"请输入答案\"))\n",
    "            break\n",
    "        except:\n",
    "            print(\"请确保输入的是一个整数\")\n",
    "            cs +=1 \n",
    "            if cs ==3:\n",
    "                print(\"连续三次输入有误，此次不得分，仍需继续作答\")\n",
    "                times += 1\n",
    "            continue\n",
    "    if user_answer == answer:\n",
    "            print (\"回答正确\")\n",
    "            score += 10\n",
    "    else:\n",
    "        print(\"回答错误\")\n",
    "    cs =0\n",
    "    times += 1\n",
    "print(f\"你的得分是{score}\")\n",
    "if score>=90:\n",
    "    print(\"太棒了\")\n",
    "elif score>60:\n",
    "    print(\"不错\")\n",
    "else:\n",
    "    print(\"要加油\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00a21e45-9161-47d2-afda-6dd39bae13d5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
